﻿Partial Public Class Wfrm_CrearSolicitud
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'session("usuario")
        If Not Page.IsPostBack Then
            txtCantidad.Attributes.Add("onkeypress", "javascript:return ValidNum(event);")
            txtNsolicitud.Attributes.Add("onkeypress", "javascript:return ValidNum(event);")

            'Session("usu") = Session("usuario")
            ViewState("usu") = Session("usuario")
            llena_combo()
            carga_bodega()
            FK_EMPRESA()

            CreaDatatable()
        End If
    End Sub
    Sub CreaDatatable() 'JQ
        Dim Dt2 As New DataTable
        Dt2.Columns.Add("")
        Dt2.Columns.Add("nCodigo_PKI")
        Dt2.Columns.Add("Producto")
        Dt2.Columns.Add("tNombre")
        Dt2.Columns.Add("CANT_SOLICITADA")
        ViewState("DT") = Dt2
    End Sub
    Sub FK_EMPRESA()
        Dim exec As New DotNetDal.SQLPersistence(False, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence

        rp.StoredProcedure = ("SP_OC_GET_FK_EMPRESA")
        rp.AddParametro(ViewState("usu"))
        exec.ExecuteDataTable(rp)

        If rp.TieneDatos Then
            ViewState("FK_EMPRESA") = rp.DtTable.Rows(0).Item(0).ToString
        End If
        If rp.Errores Then
            'erro
        Else
            'ok
        End If

    End Sub

    Protected Sub linkSolicitud_Click(ByVal sender As Object, ByVal e As EventArgs) Handles linkSolicitud.Click
        If Panel1.Visible = False Then
            Panel1.Visible = True
            Panel1.UpdateAfterCallBack = True
        Else
            Panel1.Visible = False
            Panel1.UpdateAfterCallBack = True
        End If
    End Sub
    Sub carga_bodega()
        Dim exec As New DotNetDal.SQLPersistence(False, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence

        rp.StoredProcedure = ("SP_OC_CARGA_BODEGA")
        rp.AddParametro(ViewState("usu"))
        exec.ExecuteDataTable(rp)

        If rp.TieneDatos Then
            cmbBodega.DataTextField = "DESCRIPCION"
            cmbBodega.DataValueField = "ID_BODEGA"
            cmbBodega.DataSource = rp.DtTable
            cmbBodega.DataBind()
            cmbBodega.UpdateAfterCallBack = True
        End If
    End Sub

    Sub llena_combo()
        Dim exec As New DotNetDal.SQLPersistence(False, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence

        rp.StoredProcedure = ("SP_OC_PRODUCTOS")
        exec.ExecuteDataTable(rp)

        If rp.TieneDatos Then
            cmbProducto.DataTextField = "tnombre"
            cmbProducto.DataValueField = "nCodigo_PKI"
            cmbProducto.DataSource = rp.DtTable
            cmbProducto.DataBind()
            cmbProducto.UpdateAfterCallBack = True
        End If
    End Sub

    'Sub carga_grilla()
    '    Dim Dt2 As New DataTable
    '    Dim dr As DataRow
    '    Dt2.Columns.Add("")
    '    Dt2.Columns.Add("nCodigo_PKI")
    '    Dt2.Columns.Add("Producto")
    '    Dt2.Columns.Add("tNombre")
    '    Dt2.Columns.Add("Cantidad")
    '    Dim suma As Integer

    '    If DataGrid2.Items.Count = 0 Then
    '        dr = Dt2.NewRow
    '        dr(1) = cmbProducto.SelectedValue.ToString
    '        dr(2) = cmbProducto.SelectedItem.ToString
    '        dr(3) = "0000"
    '        dr(4) = txtCantidad.Text
    '        Dt2.Rows.Add(dr)
    '    End If

    '    For i = 0 To DataGrid2.Items.Count - 1
    '        If cmbProducto.SelectedValue.ToString = DataGrid2.Items(i).Cells(1).Text.ToString Then
    '            Session("suma") = "total"
    '            AddNums(DataGrid2.Items(i).Cells(4).Text.ToString, txtCantidad.Text)
    '            dr = Dt2.NewRow
    '            dr(1) = cmbProducto.SelectedValue.ToString
    '            dr(2) = cmbProducto.SelectedItem.ToString
    '            dr(3) = "0000"
    '            dr(4) = Session("AddNums")
    '            Dt2.Rows.Add(dr)
    '            Exit For
    '        End If
    '    Next

    '    If Session("suma") <> "total" And DataGrid2.Items.Count <> 0 Then
    '        dr = Dt2.NewRow
    '        dr(1) = cmbProducto.SelectedValue.ToString
    '        dr(2) = cmbProducto.SelectedItem.ToString
    '        dr(3) = "0000"
    '        dr(4) = txtCantidad.Text
    '        Dt2.Rows.Add(dr)
    '    End If

    '    For i = 0 To DataGrid2.Items.Count - 1
    '        If cmbProducto.SelectedValue.ToString = DataGrid2.Items(i).Cells(1).Text.ToString Then
    '            DataGrid2.Items(i).Cells(1).Text = ""
    '            DataGrid2.Items(i).Cells(2).Text = ""
    '            DataGrid2.Items(i).Cells(3).Text = ""
    '            DataGrid2.Items(i).Cells(4).Text = ""
    '            DataGrid2.Items(i).Cells(0).Text = ""
    '        Else
    '            dr = Dt2.NewRow
    '            dr(1) = DataGrid2.Items(i).Cells(1).Text.ToString
    '            dr(2) = DataGrid2.Items(i).Cells(2).Text.ToString
    '            dr(3) = "0000"
    '            dr(4) = DataGrid2.Items(i).Cells(4).Text.ToString
    '            Dt2.Rows.Add(dr)
    '        End If
    '    Next

    '    Session("suma") = Nothing
    '    DataGrid2.DataSource = Dt2
    '    DataGrid2.DataBind()
    '    DataGrid2.UpdateAfterCallBack = True
    'End Sub

    Private Function SumarProducto(ByVal codProducto As String) As Decimal 'JQ
        Dim i As Integer
        For i = 0 To DataGrid2.Items.Count - 1
            If codProducto = DataGrid2.Items(i).Cells(1).Text Then
                Return DataGrid2.Items(i).Cells(4).Text
            End If
        Next
        Return 0
    End Function
    'Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
    '    If txtCantidad.Text = "" Or txtCantidad.Text = "0" Then
    '        pnl_mensaje.Visible = True
    '        pnl_mensaje.UpdateAfterCallBack = True
    '        Exit Sub
    '    End If
    '    pnl_mensaje.Visible = False
    '    pnl_mensaje.UpdateAfterCallBack = True

    '    Dim Cant As Decimal = SumarProducto(cmbProducto.SelectedValue) 'JQ

    '    If Val(txtSolicitud.Text) = 0 Then
    '        'nueva solicitud, se maneja grilla por ViewState("DT")
    '        If Cant > 0 Then
    '            Dim i As Integer
    '            For i = 0 To ViewState("DT").Rows.Count - 1
    '                If ViewState("DT").Rows(i).Item(1) = cmbProducto.SelectedValue Then
    '                    ViewState("DT").Rows(i).Item(4) = txtCantidad.Text + Cant
    '                    Exit For
    '                End If
    '            Next
    '        Else
    '            'se agrega fila al datatable
    '            Dim dr As DataRow
    '            dr = ViewState("DT").NewRow
    '            dr(0) = ""
    '            dr(1) = cmbProducto.SelectedValue.ToString
    '            dr(2) = cmbProducto.SelectedItem.ToString
    '            dr(3) = cmbProducto.SelectedItem.ToString
    '            dr(4) = txtCantidad.Text
    '            ViewState("DT").Rows.Add(dr)

    '        End If

    '        DataGrid2.DataSource = ViewState("DT")
    '        DataGrid2.DataBind()
    '        DataGrid2.UpdateAfterCallBack = True

    '    Else
    '        'se agrega producto directamente a la tabla
    '        If Cant > 0 Then
    '            ActualizaProducto(Val(txtSolicitud.Text), cmbProducto.SelectedValue, txtCantidad.Text + Cant)
    '        Else
    '            AgregaProducto(Val(txtSolicitud.Text), cmbProducto.SelectedValue, txtCantidad.Text)
    '        End If
    '        'Se carga grilla nuevamente
    '        GetProductosSolicitud()
    '    End If


    '    txtCantidad.Text = ""
    '    txtCantidad.UpdateAfterCallBack = True
    'End Sub

    'Protected Sub ImgGrabarSol_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImgGrabarSol.Click
    '    Dim exec As New DotNetDal.SQLPersistence(True, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
    '    Dim rp As New DotNetResponse.SQLPersistence

    '    rp.StoredProcedure = "SP_OC_INSERT_SOLICITUD"
    '    rp.AddParametro(ViewState("FK_EMPRESA")) '("FK_EMPRESA") 'nClinicaID de usuario, HACER SP
    '    rp.AddParametro(cmbBodega.SelectedValue) '("FK_BODEGA") 'id_bodega del combobox
    '    rp.AddParametro(ViewState("usu")) '("FK_USUARIO_CREA") 'PONDRE Tcodigo_user_PK, FVOR REVISAR
    '    rp.AddParametro(ViewState("usu"))
    '    'rp.AddParametro("") '("FECHA_CREACION")
    '    'rp.AddParametro("") '("FK_USUARIO_MODIFICA")
    '    'rp.AddParametro("") '("FECHA_MODIFICACION")
    '    ' rp.AddParametro("1") '("ESTADO_SOL")

    '    exec.ExecuteNonQuery(rp)
    '    'exec.Commit()
    '    If rp.Errores Then
    '        'error
    '    Else
    '        'ok
    '    End If

    '    For i = 0 To DataGrid2.Items.Count - 1
    '        rp.ClearParametro()
    '        rp.TieneDatos = False

    '        rp.StoredProcedure = "SP_OC_INSERT_SOLICITUD_PRODUCTO"

    '        rp.AddParametro(DataGrid2.Items(i).Cells(1).Text.ToString)
    '        rp.AddParametro(DataGrid2.Items(i).Cells(4).Text.ToString)
    '        'rp.AddParametro("0")
    '        'rp.AddParametro("0")
    '        'rp.AddParametro("")
    '        'rp.AddParametro("0")
    '        'rp.AddParametro(ViewState("usu"))
    '        rp.AddParametro(ViewState("usu"))

    '        exec.ExecuteNonQuery(rp)


    '        If rp.Errores Then
    '            'error
    '        Else
    '            'ok
    '        End If

    '    Next

    '    exec.Commit()

    'End Sub
    Sub AgregaProducto(ByVal fk_solicitud As String, ByVal fk_producto As String, ByVal Cant_sol As Decimal) 'JQ

        Dim exec As New DotNetDal.SQLPersistence(True, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence

        rp.StoredProcedure = "SP_OC_INSERT_SOLICITUD_PRODUCTO"

        rp.AddParametro(fk_solicitud)
        rp.AddParametro(fk_producto)
        rp.AddParametro(Cant_sol)
        rp.AddParametro(ViewState("usu"))

        exec.ExecuteNonQuery(rp)
        exec.Commit()
    End Sub
    Sub ActualizaProducto(ByVal fk_solicitud As String, ByVal fk_producto As String, ByVal Cant_sol As Decimal) 'JQ

        Dim exec As New DotNetDal.SQLPersistence(True, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence

        rp.StoredProcedure = "SP_OC_UPDATE_SOLICITUD_PRODUCTO"

        rp.AddParametro(fk_solicitud)
        rp.AddParametro(fk_producto)
        rp.AddParametro(Cant_sol)
        rp.AddParametro(ViewState("usu"))

        exec.ExecuteNonQuery(rp)
        exec.Commit()
    End Sub

    Sub GetProductosSolicitud()  'JQ      
        Dim exec As New DotNetDal.SQLPersistence(False, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence
        rp.StoredProcedure = "SP_OC_GET_SOLICITUD_PRODUCTO"
        rp.AddParametro(txtSolicitud.Text)
        exec.ExecuteDataTable(rp)
        'If rp.TieneDatos Then
        ViewState("DT") = rp.DtTable
        ViewState("datos") = "datos"
        DataGrid2.DataSource = rp.DtTable
        DataGrid2.DataBind()
        DataGrid2.UpdateAfterCallBack = True
        'End If

    End Sub
    Protected Sub DataGrid2_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DataGrid2.SelectedIndexChanged
        Dim exec As New DotNetDal.SQLPersistence(True, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence
        If Val(txtSolicitud.Text) = 0 Then
            Dim i As Integer
            For i = 0 To ViewState("DT").Rows.Count - 1
                If ViewState("DT").Rows(i).Item(1) = DataGrid2.SelectedItem.Cells(1).Text Then  'cmbProducto.SelectedValue Then DU
                    ViewState("DT").Rows(i).Delete()
                    Exit For
                End If
            Next

            DataGrid2.DataSource = ViewState("DT")
            DataGrid2.DataBind()
            DataGrid2.UpdateAfterCallBack = True

        Else
            'se quita fila directamente de la tabla

            For i = 0 To ViewState("DT").Rows.Count - 1
                If ViewState("DT").Rows(i).Item(0) = DataGrid2.SelectedItem.Cells(1).Text Then  'cmbProducto.SelectedValue Then DU
                    ViewState("DT").Rows(i).Delete()
                    Exit For
                End If
            Next

            'hacer sp pa eliminar de la tabla  --- parecido al update 

            rp.StoredProcedure = "SP_OC_DELETE_PRODUCTO"
            rp.AddParametro(DataGrid2.SelectedItem.Cells(1).Text)
            rp.AddParametro(DirectCast(DataGrid1.SelectedItem.Cells(0).Controls(1), Anthem.LinkButton).Text)
            'DataGrid1.SelectedItem.Cells(0).Text)
            exec.ExecuteNonQuery(rp)
            exec.Commit()
            If rp.Errores Then

            End If

            'Cargar grilla
            GetProductosSolicitud()

        End If


    End Sub

    'Sub carga()
    '    Dim Dt2 As New DataTable
    '    Dim dr As DataRow
    '    Dt2.Columns.Add("")
    '    Dt2.Columns.Add("nCodigo_PKI")
    '    Dt2.Columns.Add("Producto")
    '    Dt2.Columns.Add("tNombre")
    '    Dt2.Columns.Add("Cantidad")

    '    For i = 0 To DataGrid2.Items.Count - 1 And DataGrid2.Items(1).Cells(1).Text.ToString <> ""
    '        If DataGrid2.Items(i).Cells(1).Text.ToString <> "" Then
    '            dr = Dt2.NewRow
    '            dr(1) = DataGrid2.Items(i).Cells(1).Text.ToString
    '            dr(2) = DataGrid2.Items(i).Cells(2).Text.ToString
    '            dr(3) = "0000"
    '            dr(4) = DataGrid2.Items(i).Cells(4).Text.ToString
    '            Dt2.Rows.Add(dr)
    '        End If
    '    Next

    '    DataGrid2.DataSource = Dt2
    '    DataGrid2.DataBind()
    '    DataGrid2.UpdateAfterCallBack = True
    'End Sub

    'Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
    '    Dim exec As New DotNetDal.SQLPersistence(True, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
    '    Dim rp As New DotNetResponse.SQLPersistence
    '    Dim fecha_ini As String
    '    Dim fecha_fin As String
    '    fecha_ini = Convert.ToDateTime(txtStartDate.Text).ToString("yyyyMMdd")
    '    fecha_fin = Convert.ToDateTime(txtEndDate.Text).ToString("yyyyMMdd")

    '    rp.StoredProcedure = "SP_OC_CONSULTA_SOLICITUD_FECHA"
    '    rp.AddParametro(fecha_ini)
    '    rp.AddParametro(fecha_fin)
    '    exec.ExecuteDataTable(rp)

    '    If rp.TieneDatos Then
    '        DataGrid1.DataSource = rp.DtTable
    '        DataGrid1.DataBind()
    '        DataGrid1.UpdateAfterCallBack = True
    '    End If

    'End Sub

    'Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    '    Dim exec As New DotNetDal.SQLPersistence(True, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
    '    Dim rp As New DotNetResponse.SQLPersistence

    '    rp.StoredProcedure = "SP_OC_CONSULTA_SOLICITUD_IDSOLICITUD"
    '    rp.AddParametro(txtNsolicitud.Text)
    '    exec.ExecuteDataTable(rp)

    '    If rp.TieneDatos Then
    '        DataGrid1.DataSource = rp.DtTable
    '        DataGrid1.DataBind()
    '        DataGrid1.UpdateAfterCallBack = True
    '    End If
    'End Sub

    Protected Sub DataGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DataGrid1.SelectedIndexChanged
        txtSolicitud.Text = DirectCast(DataGrid1.SelectedItem.Cells(0).Controls(1), Anthem.LinkButton).Text
        txtSolicitud.UpdateAfterCallBack = True
        GetProductosSolicitud()
    End Sub

    'Protected Sub Aceptar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Aceptar.Click, Aceptar.Click
    '    Dim exec As New DotNetDal.SQLPersistence(True, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
    '    Dim rp As New DotNetResponse.SQLPersistence

    '    rp.StoredProcedure = "SP_OC_INSERT_SOLICITUD"
    '    rp.AddParametro(ViewState("FK_EMPRESA")) '("FK_EMPRESA") 'nClinicaID de usuario, HACER SP
    '    rp.AddParametro(cmbBodega.SelectedValue) '("FK_BODEGA") 'id_bodega del combobox
    '    rp.AddParametro(ViewState("usu")) '("FK_USUARIO_CREA") 'PONDRE Tcodigo_user_PK, FVOR REVISAR
    '    rp.AddParametro(ViewState("usu"))
    '    'rp.AddParametro("") '("FECHA_CREACION")
    '    'rp.AddParametro("") '("FK_USUARIO_MODIFICA")
    '    'rp.AddParametro("") '("FECHA_MODIFICACION")
    '    ' rp.AddParametro("1") '("ESTADO_SOL")

    '    exec.ExecuteNonQuery(rp)
    '    'exec.Commit()
    '    If rp.Errores Then
    '        'error
    '    Else
    '        'ok
    '    End If

    '    For i = 0 To DataGrid2.Items.Count - 1
    '        rp.ClearParametro()
    '        rp.TieneDatos = False

    '        rp.StoredProcedure = "SP_OC_INSERT_SOLICITUD_PRODUCTO"

    '        rp.AddParametro(DataGrid2.Items(i).Cells(1).Text.ToString)
    '        rp.AddParametro(DataGrid2.Items(i).Cells(4).Text.ToString)
    '        'rp.AddParametro("0")
    '        'rp.AddParametro("0")
    '        'rp.AddParametro("")
    '        'rp.AddParametro("0")
    '        'rp.AddParametro(ViewState("usu"))
    '        rp.AddParametro(ViewState("usu"))

    '        exec.ExecuteNonQuery(rp)


    '        If rp.Errores Then
    '            'error
    '        Else
    '            'ok
    '        End If

    '    Next

    '    exec.Commit()

    'End Sub

    Protected Sub Aceptar1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Aceptar1.Click
        Dim exec As New DotNetDal.SQLPersistence(True, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence
        Dim fecha_ini As String
        Dim fecha_fin As String
        fecha_ini = Convert.ToDateTime(txtStartDate.Text).ToString("yyyyMMdd")
        fecha_fin = Convert.ToDateTime(txtEndDate.Text).ToString("yyyyMMdd")

        rp.StoredProcedure = "SP_OC_CONSULTA_SOLICITUD_FECHA"
        rp.AddParametro(fecha_ini)
        rp.AddParametro(fecha_fin)
        exec.ExecuteDataTable(rp)

        If rp.TieneDatos Then
            DataGrid1.DataSource = rp.DtTable
            DataGrid1.DataBind()
            DataGrid1.UpdateAfterCallBack = True
        End If

    End Sub

    Protected Sub buscar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles buscar.Click
        Dim exec As New DotNetDal.SQLPersistence(True, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence

        rp.StoredProcedure = "SP_OC_CONSULTA_SOLICITUD_IDSOLICITUD"
        rp.AddParametro(txtNsolicitud.Text)
        exec.ExecuteDataTable(rp)

        If rp.TieneDatos Then
            DataGrid1.DataSource = rp.DtTable
            DataGrid1.DataBind()
            DataGrid1.UpdateAfterCallBack = True
        End If
    End Sub

    Protected Sub Aceptar2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Aceptar2.Click
        If txtCantidad.Text = "" Or txtCantidad.Text = "0" Then
            pnl_mensaje.Visible = True
            pnl_mensaje.UpdateAfterCallBack = True
            Exit Sub
        End If
        pnl_mensaje.Visible = False
        pnl_mensaje.UpdateAfterCallBack = True

        Dim Cant As Decimal = SumarProducto(cmbProducto.SelectedValue) 'JQ

        If Val(txtSolicitud.Text) = 0 Then
            'nueva solicitud, se maneja grilla por ViewState("DT")
            If Cant > 0 Then
                Dim i As Integer
                For i = 0 To ViewState("DT").Rows.Count - 1
                    If ViewState("DT").Rows(i).Item(1) = cmbProducto.SelectedValue Then
                        ViewState("DT").Rows(i).Item(4) = txtCantidad.Text + Cant
                        Exit For
                    End If
                Next
            Else
                'se agrega fila al datatable
                Dim dr As DataRow
                dr = ViewState("DT").NewRow
                dr(0) = ""
                dr(1) = cmbProducto.SelectedValue.ToString
                dr(2) = cmbProducto.SelectedItem.ToString
                dr(3) = cmbProducto.SelectedItem.ToString
                dr(4) = txtCantidad.Text
                ViewState("DT").Rows.Add(dr)

            End If

            DataGrid2.DataSource = ViewState("DT")
            DataGrid2.DataBind()
            DataGrid2.UpdateAfterCallBack = True

        Else
            'se agrega producto directamente a la tabla
            If Cant > 0 Then
                ActualizaProducto(Val(txtSolicitud.Text), cmbProducto.SelectedValue, txtCantidad.Text + Cant)
            Else
                AgregaProducto(Val(txtSolicitud.Text), cmbProducto.SelectedValue, txtCantidad.Text)
            End If
            'Se carga grilla nuevamente
            GetProductosSolicitud()
        End If


        txtCantidad.Text = ""
        txtCantidad.UpdateAfterCallBack = True
    End Sub

    Protected Sub Aceptar3_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Aceptar3.Click
        Dim exec As New DotNetDal.SQLPersistence(True, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence

        rp.StoredProcedure = "SP_OC_INSERT_SOLICITUD"
        rp.AddParametro(ViewState("FK_EMPRESA")) '("FK_EMPRESA") 'nClinicaID de usuario, HACER SP
        rp.AddParametro(cmbBodega.SelectedValue) '("FK_BODEGA") 'id_bodega del combobox
        rp.AddParametro(ViewState("usu")) '("FK_USUARIO_CREA") 'PONDRE Tcodigo_user_PK, FVOR REVISAR
        rp.AddParametro(ViewState("usu"))
        'rp.AddParametro("") '("FECHA_CREACION")
        'rp.AddParametro("") '("FK_USUARIO_MODIFICA")
        'rp.AddParametro("") '("FECHA_MODIFICACION")
        ' rp.AddParametro("1") '("ESTADO_SOL")

        exec.ExecuteNonQuery(rp)
        'exec.Commit()
        If rp.Errores Then
            'error
        Else
            'ok
        End If

        For i = 0 To DataGrid2.Items.Count - 1
            rp.ClearParametro()
            rp.TieneDatos = False

            rp.StoredProcedure = "SP_OC_INSERT_SOLICITUD_PRODUCTO"

            rp.AddParametro(DataGrid2.Items(i).Cells(1).Text.ToString)
            rp.AddParametro(DataGrid2.Items(i).Cells(4).Text.ToString)
            'rp.AddParametro("0")
            'rp.AddParametro("0")
            'rp.AddParametro("")
            'rp.AddParametro("0")
            'rp.AddParametro(ViewState("usu"))
            rp.AddParametro(ViewState("usu"))

            exec.ExecuteNonQuery(rp)


            If rp.Errores Then
                'error
            Else
                'ok
            End If

        Next

        exec.Commit()
    End Sub

    Protected Sub txtEndDate_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtEndDate.TextChanged

    End Sub
End Class